y=int(input())
d=int(input())

month=[0,31,28,31,30,31,30,31,31,30,31,30,31]

if y%400==0 or (y%4==0 and y%100!=0):
    month[2]+=1

i=0
while d>month[i]:
    d-=month[i]
    i+=1

print(i)
print(d)